package com.billard.controller;


import com.billard.result.Result;
import com.billard.websocket.TableStatusPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class HealthController {
    @Autowired
    TableStatusPublisher tableStatusPublisher;

    @GetMapping("/health")
    public Result<String> health() {

        return Result.success("OK");
    }
    /**
     * 【测试专用】模拟创建预约并发送通知
     */
    @PostMapping("/test/create")
    @PreAuthorize("hasRole('SUPER_ADMIN')")
    public Result<String> testCreateReservation() {
        // 模拟一条预约提醒
        tableStatusPublisher.publishReservationReminder(
                "【测试】新预约：张三 预约 球台1 时间：14:00-16:00"
        );
        return Result.success("已发送测试预约提醒");
    }

    /**
     * 【测试专用】模拟确认预约并更新球台状态
     */
    @PostMapping("/test/confirm")
    @PreAuthorize("hasRole('SUPER_ADMIN')")
    public Result<String> testConfirmReservation() {
        // 模拟球台状态变更
        Map<String, Object> payload = new HashMap<>();
        payload.put("tableId", 1);
        payload.put("status", "RESERVED");
        payload.put("message", "球台1 已被确认预约");
        payload.put("timestamp", System.currentTimeMillis());

        tableStatusPublisher.publishTableStatusChange(1L);
        return Result.success("已发送球台状态更新");
    }

    @GetMapping("/webSocketTest")
    @PreAuthorize("hasRole('SUPER_ADMIN')")
    public Result<String> testNotification() {
        tableStatusPublisher.publishSystemNotification("test测试websocket");
        return Result.success("成功发送");
    }



}


